using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace SmartRename
{
    public partial class PathPicker : UserControl
    {

        public delegate void FileListReloadedHandler();
        public event FileListReloadedHandler FileListReloaded;

        public PathPicker()
        {
            InitializeComponent();
        }

        private List<RenameFile> _renameList;
        public List<RenameFile> RenameList
        {
            get { return _renameList; }
        }

        private SearchOption SearchOption
        {
            get
            {
                SearchOption option = SearchOption.TopDirectoryOnly;
                if (this.chkIncludeSubdirectories.Checked)
                {
                    option = SearchOption.AllDirectories;
                }
                return option;
            }
        }

        private void getFileList_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtRootDirectory.Text))
            {
                this._renameList = new List<RenameFile>();
                foreach (string filename in Directory.GetFiles(this.txtRootDirectory.Text, this.txtSearchPattern.Text, this.SearchOption))
                {
                    this._renameList.Add(new RenameFile(filename));
                }
                if (FileListReloaded != null)
                {
                    this.FileListReloaded();
                }
            }
        }

        private void cmdDirectoryDialog_Click_1(object sender, EventArgs e)
        {
            if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                this.txtRootDirectory.Text = this.folderBrowserDialog1.SelectedPath;
            }
        }
    }
}
